package com.zut.yunxi.yunxi.service.impl;

import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zut.yunxi.yunxi.dao.TProductDao;
import com.zut.yunxi.yunxi.entity.TOrderEntity;
import com.zut.yunxi.yunxi.entity.TProductEntity;
import com.zut.yunxi.yunxi.service.TProductService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("tProductService")
public class TProductServiceImpl extends ServiceImpl<TProductDao, TProductEntity> implements TProductService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        String id = (String) params.get("id");
        QueryWrapper<TProductEntity> queryWrapper=new QueryWrapper<TProductEntity>();
        if(StringUtils.isNotBlank(id))
            queryWrapper.eq("business_id",id);
        if(StringUtils.isNotBlank(key))
        {
            queryWrapper.eq("id",key).or().like("name",key);
        }
        IPage<TProductEntity> page = this.page(
                new Query<TProductEntity>().getPage(params),
              queryWrapper

        );

        return new PageUtils(page);
    }
    @Override
    public PageUtils queryPageshop(Map<String, Object> params) {
        QueryWrapper<TProductEntity> queryWrapper=new QueryWrapper<TProductEntity>();

        IPage<TProductEntity> page = this.page(
                new Query<TProductEntity>().getPage(params),
                queryWrapper

        );

        return new PageUtils(page);
    }

}